class code1 {
    //爬楼梯
    //空间优化:不用数组
    public int climbStairs(int n) {
        int a = 1;//1
        int b = 2;//2
        int c = 0;

        if(n<=2) {
            return n==1? 1:2;
        }

        for(int i=3;i<=n;i++) {
            c = a + b;
            a = b;
            b = c;
        }

        return c;
    }
}